﻿#region Licence
// <copyright file="Core/BarreEtatService.cs" company="Kopigi">
// Copyright © Kopigi 2014
// </copyright>
// ****************************************************************************
// <author>Marc PLESSIS</author>
// <date>11/10/2014</date>
// <project>Nentang.wpf</project>
// <web>http://nentang.codeplex.com</web>
// <license>
// The MIT License (MIT)
// 
// Copyright (c) 2013 Marc Plessis
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// 
// </license>
#endregion
#region using

using System.Windows.Media;
using Core.Messages;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Messaging;
using Interfaces;
using Interfaces.Enums;

#endregion

namespace Core.Services
{
    /// <summary>
    /// Permet de gérer la barre d'état
    /// </summary>
    public class BarreEtatService : IServiceBarreEtat
    {
        private ViewModelBase _currentUc;

        /// <summary>
        /// Efface le contenu libre de la barre d'état
        /// </summary>
        public void ClearContentFree()
        {
            Messenger.Default.Send<RefreshContentFreeMessage>(new RefreshContentFreeMessage { IsClear = true });
        }

        /// <summary>
        /// Efface les messages de la barre d'etat
        /// </summary>
        public void ClearMessage()
        {
            Messenger.Default.Send<RefreshBarreEtatMessage>(new RefreshBarreEtatMessage { IsClear = true });
        }

        /// <summary>
        /// Permet de charger un contenu libre dans la barre d'état
        /// </summary>
        /// <param name="uc">UserControl à charger</param>
        public void SetContentFree(ViewModelBase uc)
        {
            _currentUc = uc;
            Messenger.Default.Send<RefreshContentFreeMessage>(new RefreshContentFreeMessage { IsClear = false, UControl = uc });
        }

        /// <summary>
        /// Permet d'inscrire un message dans la barre d'état
        /// </summary>
        /// <param name="message"></param>
        /// <param name="icon"></param>
        public void SetMessage(string message, IconBarreEtatEnum icon)
        {
            Messenger.Default.Send<RefreshBarreEtatMessage>(new RefreshBarreEtatMessage { IsClear = false, Message = message, IconGeometry = GetGeometryIcon(icon)});
        }

        /// <summary>
        /// Permet de récupérer le contenu actuel pour éventuellement le ré-injecter plus tard
        /// </summary>
        /// <returns></returns>
        public ViewModelBase GetContentFree()
        {
            return _currentUc;
        }

        #region private

        /// <summary>
        /// Permet de créer la geometry de l'icon
        /// </summary>
        /// <param name="icon"></param>
        /// <returns></returns>
        private Geometry GetGeometryIcon(IconBarreEtatEnum icon)
        {
            switch (icon)
            {
                case IconBarreEtatEnum.Generic:
                    return Geometry.Parse("F1 M 3.348,1.333 L 9.333,5.105 C 9.593,5.365 9.593,5.787 9.333,6.047 L 3.348,9.333 C 2.980,9.333 2.681,9.035 2.681,8.667 L 2.681,2.000 C 2.681,1.632 2.980,1.333 3.348,1.333 Z M 0.667,0.000 L 1.333,0.000 C 1.702,0.000 2.000,0.299 2.000,0.667 L 2.000,15.334 C 2.000,15.702 1.702,16.000 1.333,16.000 L 0.667,16.000 C 0.299,16.000 0.000,15.702 0.000,15.334 L 0.000,0.667 C 0.000,0.299 0.299,0.000 0.667,0.000 Z");

                case IconBarreEtatEnum.Save:
                    return Geometry.Parse("F1 M 8.444,1.778 L 8.444,6.222 L 10.667,6.222 L 10.667,1.778 L 8.444,1.778 Z M 14.223,3.222 L 12.777,1.778 L 12.444,1.778 L 12.444,7.556 L 3.556,7.556 L 3.556,1.778 L 1.778,1.778 L 1.778,14.223 L 14.223,14.223 L 14.223,3.222 Z M 0.000,0.000 L 13.444,0.000 L 16.000,2.556 L 16.000,16.000 L 0.000,16.000 L 0.000,0.000 Z");

                case IconBarreEtatEnum.Wait:
                    return
                        Geometry.Parse(
                            "F1 M 10.9609,19.0872C 10.9609,19.0872 9.76041,11.487 7.29817,11.487C 5.16667,11.487 3.93033,17.2383 3.64388,18.724C 4.91992,17.8125 6.95508,16.138 7.50391,15.5912C 7.50391,15.5912 9.02084,18.1263 10.4805,19.0872M 3.64909,2.24609C 3.64909,2.24609 4.01107,4.89713 4.82357,6.972C 6.14713,6.3444 8.7526,5.33268 9.98959,6.37891C 10.6575,4.46028 10.9466,2.24609 10.9466,2.24609M 0,0L 14.5964,0L 14.5964,2.24609L 12.9128,2.24609C 12.6315,4.18945 11.6979,9.23047 8.96875,10.6673C 11.6979,12.1042 12.6315,17.1445 12.9128,19.0872L 14.5964,19.0872L 14.5964,21.3333L 0,21.3333L 0,19.0872L 1.6836,19.0872C 1.96484,17.1445 2.89779,12.1042 5.6276,10.6673C 2.89779,9.23047 1.96484,4.18945 1.6836,2.24609L 0,2.24609M 7.70768,14.0169C 7.9362,14.0169 8.11784,14.2019 8.11784,14.4284C 8.11784,14.6549 7.9362,14.8372 7.70768,14.8372C 7.48177,14.8372 7.29817,14.6549 7.29817,14.4284C 7.29817,14.2019 7.48177,14.0169 7.70768,14.0169 Z M 7.70768,12.513C 7.9362,12.513 8.11784,12.6966 8.11784,12.9245C 8.11784,13.151 7.9362,13.3333 7.70768,13.3333C 7.48177,13.3333 7.29817,13.151 7.29817,12.9245C 7.29817,12.6966 7.48177,12.513 7.70768,12.513 Z");

                default:
                    return
                        Geometry.Parse(
                            "F1 M 3.348,1.333 L 9.333,5.105 C 9.593,5.365 9.593,5.787 9.333,6.047 L 3.348,9.333 C 2.980,9.333 2.681,9.035 2.681,8.667 L 2.681,2.000 C 2.681,1.632 2.980,1.333 3.348,1.333 Z M 0.667,0.000 L 1.333,0.000 C 1.702,0.000 2.000,0.299 2.000,0.667 L 2.000,15.334 C 2.000,15.702 1.702,16.000 1.333,16.000 L 0.667,16.000 C 0.299,16.000 0.000,15.702 0.000,15.334 L 0.000,0.667 C 0.000,0.299 0.299,0.000 0.667,0.000 Z");
            }
        }
        #endregion
    }
}
